package com.ruoyi.system.service.impl;

import java.util.ArrayList;
import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.VideoStreamMapper;
import com.ruoyi.system.domain.VideoStream;
import com.ruoyi.system.service.IVideoStreamService;
import com.ruoyi.common.core.text.Convert;

/**
 * 视频流信息Service业务层处理
 * 
 * @author wsx
 * @date 2025-07-30
 */
@Service
public class VideoStreamServiceImpl implements IVideoStreamService {
    @Autowired
    private VideoStreamMapper videoStreamMapper;

    /**
     * 查询视频流信息
     * 
     * @param streamId 视频流信息主键
     * @return 视频流信息
     */
    @Override
    public VideoStream selectVideoStreamByStreamId(Long streamId) {
        return videoStreamMapper.selectVideoStreamByStreamId(streamId);
    }

    /**
     * 查询视频流信息列表
     * 
     * @param videoStream 视频流信息
     * @return 视频流信息
     */
    @Override
    public List<VideoStream> selectVideoStreamList(VideoStream videoStream) {
        videoStream.setDelFlag("0");
        return videoStreamMapper.selectVideoStreamList(videoStream);
    }

    /**
     * 新增视频流信息
     * 
     * @param videoStream 视频流信息
     * @return 结果
     */
    @Override
    public int insertVideoStream(VideoStream videoStream) {
        videoStream.setCreateTime(DateUtils.getNowDate());
        return videoStreamMapper.insertVideoStream(videoStream);
    }

    /**
     * 修改视频流信息
     * 
     * @param videoStream 视频流信息
     * @return 结果
     */
    @Override
    public int updateVideoStream(VideoStream videoStream) {
        videoStream.setUpdateTime(DateUtils.getNowDate());
        return videoStreamMapper.updateVideoStream(videoStream);
    }

    /**
     * 批量删除视频流信息
     * 
     * @param streamIds 需要删除的视频流信息主键
     * @return 结果
     */
    @Override
    public int deleteVideoStreamByStreamIds(String streamIds) {
        return videoStreamMapper.deleteVideoStreamByStreamIds(Convert.toStrArray(streamIds));
    }

    /**
     * 批量删除视频流信息-逻辑删除
     * 
     * @param streamIds 需要修改的视频流信息主键集合
     * @return 结果
     */
    @Override
    public int updateDelFlag(String streamIds) {
        Long[] streamIdArray = Convert.toLongArray(streamIds);
        for (Long streamId : streamIdArray) {
            VideoStream videoStream = new VideoStream();
            videoStream.setDelFlag("2");
            videoStream.setUpdateTime(DateUtils.getNowDate());
            videoStream.setStreamId(streamId);
            videoStreamMapper.updateVideoStream(videoStream);
        }
        return streamIdArray.length;
    }

    /**
     * 删除视频流信息信息
     * 
     * @param streamId 视频流信息主键
     * @return 结果
     */
    @Override
    public int deleteVideoStreamByStreamId(Long streamId) {
        return videoStreamMapper.deleteVideoStreamByStreamId(streamId);
    }

    @Override
    public List<VideoStream> getSaveVideoStreamList() {
        VideoStream videoStream = new VideoStream();
        videoStream.setDelFlag("0");
        videoStream.setStatus("0");
        return videoStreamMapper.selectVideoStreamList(videoStream);
    }

    @Override
    public List<VideoStream> selectVideoStreamListByIds(List<String> streamIdList) {
        if (streamIdList == null || streamIdList.isEmpty()) {
            return new ArrayList<>();
        }
        return videoStreamMapper.selectVideoStreamListByIds(streamIdList);
    }

}
